﻿using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;

namespace Mitmar.Web.Mvc.DNN
{

    public interface IRequest
    {

        NameValueCollection QueryString { get; set; }
        NameValueCollection Form { get; set; }
        HttpCookieCollection Cookies { get; set; }
        NameValueCollection Headers { get; set; }
        List<HttpPostedFile> Files { get; set; }
        string ApplicationPath { get; set; }
        string RequestType { get; set; }
        bool IsAuthenticated { get; set; }
        string UserName { get; set; }

        NameValueCollection ServerVariables { get; set; }
    }

    public class ASPRequest : IRequest
    {

        HttpRequest _request = HttpContext.Current.Request;

        private List<HttpPostedFile> _files;
        public string ApplicationPath
        {
            get { return _request.ApplicationPath; }
            set { }
        }

        public System.Web.HttpCookieCollection Cookies
        {
            get { return _request.Cookies; }
            set { }
        }

        public List<HttpPostedFile> Files
        {
            get
            {
                if (_files == null)
                {
                    _files = new List<HttpPostedFile>();
                    if (_request.Files.Count > 0)
                    {
                        for (var i = 0; i <= _request.Files.Count - 1; i++)
                        {
                            _files.Add(_request.Files[i]);
                        }
                    }
                }
                return _files;
            }
            set { }
        }

        public NameValueCollection Form
        {
            get { return _request.Form; }
            set { }
        }

        public NameValueCollection Headers
        {
            get { return _request.Headers; }
            set { }
        }

        public bool IsAuthenticated
        {
            get { return _request.IsAuthenticated; }
            set { }
        }

        public string UserName
        {
            get { return HttpContext.Current.User.Identity.Name; }
            set { }
        }


        public NameValueCollection QueryString
        {
            get { return _request.QueryString; }
            set { }
        }

        public string RequestType
        {
            get { return _request.RequestType; }
            set { }
        }

        public NameValueCollection ServerVariables
        {
            get { return _request.ServerVariables; }
            set { }
        }

    }

}

